package com.ruoyi.web.controller.warehouseManagement;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TransferStockIn;
import com.ruoyi.system.service.ITransferStockInService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 调拨入库 Controller
 *
 * @author ruoyi
 * @date 2025-06-01
 */
@Api(tags="调拨入库")
@RestController
@RequestMapping("/system/transferStockIn")
public class TransferStockInController extends BaseController
{
    @Autowired
    private ITransferStockInService transferStockInService;

    /**
     * 通过调入仓库名称和调出仓库名称查询调拨入库列表
     */
    @ApiOperation("通过调入仓库名称和调出仓库名称查询调拨入库列表")
    @PreAuthorize("@ss.hasPermi('system:in:list')")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam (required = false) String inWarehouseName,@RequestParam (required = false) String outWarehouseName)
    {
        startPage();
        List<TransferStockIn> list = transferStockInService.selectTransferStockInListByName(inWarehouseName,outWarehouseName);
        return getDataTable(list);
    }

    /**
     * 导出调拨入库列表
     */
    @ApiOperation("导出调拨入库列表")
    @PreAuthorize("@ss.hasPermi('system:in:export')")
    @Log(title = "调拨入库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestParam (required = false) String inWarehouseName,@RequestParam (required = false) String outWarehouseName)
    {
        List<TransferStockIn> list = transferStockInService.selectTransferStockInListByName(inWarehouseName,outWarehouseName);
        ExcelUtil<TransferStockIn> util = new ExcelUtil<TransferStockIn>(TransferStockIn.class);
        util.exportExcel(response, list, "调拨入库数据");
    }

    /**
     * 通过id获取调拨入库详细信息
     */
    @ApiOperation("通过id获取调拨入库详细信息")
    @PreAuthorize("@ss.hasPermi('system:in:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(transferStockInService.selectTransferStockInById(id));
    }

    /**
     * 新增调拨入库
     */
    @ApiOperation("新增调拨入库")
    @PreAuthorize("@ss.hasPermi('system:in:add')")
    @Log(title = "调拨入库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TransferStockIn transferStockIn)
    {
        return toAjax(transferStockInService.insertTransferStockIn(transferStockIn));
    }

    /**
     * 修改调拨入库
     */
    @ApiOperation("修改调拨入库")
    @PreAuthorize("@ss.hasPermi('system:in:edit')")
    @Log(title = "调拨入库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TransferStockIn transferStockIn)
    {
        return toAjax(transferStockInService.updateTransferStockIn(transferStockIn));
    }

    /**
     * 通过id批量删除调拨入库信息
     */
    @ApiOperation("通过id批量删除调拨入库信息")
    @PreAuthorize("@ss.hasPermi('system:in:remove')")
    @Log(title = "调拨入库", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(transferStockInService.deleteTransferStockInByIds(ids));
    }
}
